#ifndef _H_CARMELA_SDK_
#define _H_CARMELA_SDK_

#ifdef __cplusplus
extern "C" {
#endif

#include "carmela_util.h"

#define MQ_COMM_PROTO_VERSION_1			'1'

#define MQ_STORE_NAME_MAX_LEN			255
#define MQ_TOPIC_NAME_MAX_LEN			255
#define MQ_SUBSCRIBE_GROUP_NAME_MAX_LEN		255

#define MQ_BROKER_IP_DEFAULT			"0.0.0.0"
#define MQ_BROKER_TOOL_IP_DEFAULT		"127.0.0.1"
#define MQ_BROKER_PORT_DEFAULT			13631
#define MQ_BROKER_TIMEOUT_DEFAULT		60
#define MQ_BROKER_HEARTBEAT_DEFAULT		20

#define MQ_PROCESSCODE_CREATESTORE_REQUEST		" CSQ"
#define MQ_PROCESSCODE_CREATESTORE_RESPONSE		" CSP"
#define MQ_PROCESSCODE_DESTROYSTORE_REQUEST		" DSQ"
#define MQ_PROCESSCODE_DESTROYSTORE_RESPONSE		" DSP"
#define MQ_PROCESSCODE_CREATETOPIC_REQUEST		" CTQ"
#define MQ_PROCESSCODE_CREATETOPIC_RESPONSE		" CTP"
#define MQ_PROCESSCODE_DESTROYTOPIC_REQUEST		" DTQ"
#define MQ_PROCESSCODE_DESTROYTOPIC_RESPONSE		" DTP"
#define MQ_PROCESSCODE_PRODUCEMESSAGE_REQUEST		" PMQ"
#define MQ_PROCESSCODE_PRODUCEMESSAGE_RESPONSE		" PMP"
#define MQ_PROCESSCODE_SUBSCRIBEMESSAGE_REQUEST		" SMQ"
#define MQ_PROCESSCODE_SUBSCRIBEMESSAGE_RESPONSE	" SMP"
#define MQ_PROCESSCODE_CONSUMEMESSAGE_REQUEST		" CMQ"
#define MQ_PROCESSCODE_CONSUMEMESSAGE_RESPONSE		" CMP"
#define MQ_PROCESSCODE_HEARTBEAT_REQUEST		" HBQ"
#define MQ_PROCESSCODE_HEARTBEAT_RESPONSE		" HBP"
#define MQ_PROCESSCODE_PRODUCEDELAYMESSAGE_REQUEST	"PDMQ"
#define MQ_PROCESSCODE_PRODUCEDELAYMESSAGE_RESPONSE	"PDMP"
#define MQ_PROCESSCODE_CANCELDELAYMESSAGE_REQUEST	"CDMQ"
#define MQ_PROCESSCODE_CANCELDELAYMESSAGE_RESPONSE	"CDMP"

union MQProcessCode
{
	char		str[ 4 ] ;
	uint32_t	u32 ;
} ;

#define MQ_COMM_PREHEAD_LEN			4

#define MQSDK_SUCCESS				0
#define MQSDK_ERROR_MALLOC			10
#define MQSDK_ERROR_TIMERFD_CREATE		11
#define MQSDK_ERROR_TIMERFD_SETTIME		12
#define MQSDK_ERROR_GET_IP			21
#define MQSDK_ERROR_SYSCALL			22
#define MQSDK_ERROR_INTERNAL			90
#define MQSDK_ERROR_MESSAGE_TOO_SHORT		100
#define MQSDK_ERROR_VERSION_INVALID		101
#define MQSDK_ERROR_PROCESS_CODE_INVALID	102
#define MQSDK_ERROR_LENGTH_FIELD_TOO_BIG	103
#define MQSDK_ERROR_CONNECT			110
#define MQSDK_ERROR_RECEIVE			111
#define MQSDK_ERROR_SEND			112
#define MQSDK_ERROR_RESIZE_BUFFER		120

#define MQSDK_ERROR_MAKE_STORE_PATH		1501
#define MQSDK_ERROR_REMOVE_STORE_PATH		1502
#define MQSDK_ERROR_STORE_NOT_EXIST		1521
#define MQSDK_ERROR_STORE_EXIST			1522

#define MQSDK_ERROR_CREATE_MSG_DATA_FILE	1611
#define MQSDK_ERROR_LSEEK_MSG_DATA_FILE		1612
#define MQSDK_ERROR_LWRITE_MSG_DATA_FILE	1613
#define MQSDK_ERROR_LOAD_MSG_DATA_FILE		1614
#define MQSDK_ERROR_MSG_DATA_FILE_SIZE_INVALID	1615

#define MQSDK_ERROR_MAKE_TOPIC_PATH		1701
#define MQSDK_ERROR_REMOVE_TOPIC_PATH		1702
#define MQSDK_ERROR_CREATE_TOPIC_FILE		1711
#define MQSDK_ERROR_LSEEK_TOPIC_FILE		1712
#define MQSDK_ERROR_LWRITE_TOPIC_FILE		1713
#define MQSDK_ERROR_LOAD_TOPIC_FILE		1714
#define MQSDK_ERROR_TOPIC_FILE_SIZE_INVALID	1715
#define MQSDK_ERROR_TOPIC_NOT_EXIST_IN_STORE	1721
#define MQSDK_ERROR_TOPIC_EXIST_IN_STORE	1722

#define MQSDK_ERROR_CREATE_DELAY_MSG_FILE	1811
#define MQSDK_ERROR_LSEEK_DELAY_MSG_FILE	1812
#define MQSDK_ERROR_LWRITE_DELAY_MSG_FILE	1813
#define MQSDK_ERROR_LOAD_DELAY_MSG_FILE		1814
#define MQSDK_ERROR_DELAY_MSG_FILE_SIZE_INVALID	1815
#define MQSDK_ERROR_DELAY_MSG_OFFSET_IS_TOO_BIG	1816
#define MQSDK_ERROR_DELAY_MSG_OFFSET_CLEANED	1816
#define MQSDK_ERROR_DELAY_MSG_OFFSET_INVALID	1817
#define MQSDK_ERROR_DELAY_MSG_SENT_FLAG_INVALID	1818
#define MQSDK_ERROR_DELAY_MSG_NOT_EXIST_IN_STORE	1821

struct MQSdkContent ;

void MQSetLogEnv( int log_level , char *format , ... );

struct MQSdkContent *MQAllocContent( char *broker_ip , uint16_t broker_port );
void MQFreeContent( struct MQSdkContent *sdk );

int MQCreateStore( struct MQSdkContent *sdk , char *store_name );
int MQDestroyStore( struct MQSdkContent *sdk , char *store_name );

int MQCreateTopic( struct MQSdkContent *sdk , char *store_name , char *topic_name );
int MQDestroyTopic( struct MQSdkContent *sdk , char *store_name , char *topic_name );

int MQProduceMessage( struct MQSdkContent *sdk , char *store_name , char *topic_name , char *tags , char *msg_data , uint64_t *p_msg_offset );

int MQBeginSubscribeMessage( struct MQSdkContent *sdk , char *store_name , char *topic_name , char *subscribe_group_name );
int MQConsumeMessage( struct MQSdkContent *sdk , char **pp_topic_name , char **pp_tags , uint32_t *p_msg_data_len , char **pp_msg_data , uint64_t *p_topic_offset );
int MQEndSubscribeMessage( struct MQSdkContent *sdk );

int MQProduceDelayMessage( struct MQSdkContent *sdk , uint32_t delay_seconds , char *store_name , char *topic_name , char *tags , char *msg_data , uint64_t *p_delay_msg_offset );
int MQCancelDelayMessage( struct MQSdkContent *sdk , char *store_name , uint64_t delay_msg_offset );

int MQConnect( struct MQSdkContent *sdk );
int MQDisconnect( struct MQSdkContent *sdk );

#ifdef __cplusplus
}
#endif

#endif

